import { reqCategoryList, reqGetBannerList, reqGetFloorList } from "@/api";

const state = {
  categoryList: [],
  bannerList: [],
  floorList: []
};
const mutations = {
  SET_CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList;
  },
  SET_BANNERLOST(state, bannerList) {
    state.bannerList = bannerList
  },
  SET_FLOORLIST(state, floorList) {
    state.floorList = floorList
  }
};
const actions = {
  async get_categoryList({ commit }) {
    try {
      let result = await reqCategoryList();
      if (result.code === 200) {
        commit("SET_CATEGORYLIST", result.data);
      } else {
        alert("获取三级数据失败");
      }
    } catch (error) {
      alert("请求获取三级数据失败");
    }
  },
  async get_bannerList({ commit }) {
    try {
      let result = await reqGetBannerList()
      if (result.code === 200) {
        commit('SET_BANNERLOST', result.data)
      } else {
        alert('获取banner失败')
      }
    } catch (error) {
      alert('请求获取banner失败')

    }
  },
  async get_floorList({ commit }) {
    try {
      let result = await reqGetFloorList()
      if (result.code === 200) {
        commit('SET_FLOORLIST', result.data)
      } else {
        alert('获取floor数据失败')
      }
    } catch (error) {
      alert('请求获取floor数据失败')

    }
  }
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
